<%--
  Created by IntelliJ IDEA.
  User: 22328
  Date: 2021/2/10
  Time: 21:23
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html class="x-admin-sm">
<head>
    <meta charset="UTF-8">
    <title>商品更新</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
    <link rel="stylesheet" href="./css/font.css">
    <link rel="stylesheet" href="./css/xadmin.css">
    <script type="text/javascript" src="./lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="./js/xadmin.js"></script>
</head>
<body>
<div class="layui-fluid">
    <div class="layui-row">
        <form class="layui-form layui-form-pane" onsubmit="return false">
            <div class="layui-form-item" style="display: none">
                <label for="goods_img" class="layui-form-label">
                    商品ID
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="goods_id" name="goods_id" value="${goodsInfo.id}" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">商品分类</label>
                <div class="layui-input-inline">
                    <select id="goods_status" name="goods_status">
                        <c:if test="${goodsInfo.goodsStatus == 1}">
                            <option value="1">上架</option>
                            <option value="0">下架</option>
                        </c:if>
                        <c:if test="${goodsInfo.goodsStatus == 0}">
                            <option value="0">下架</option>
                            <option value="1">上架</option>
                        </c:if>
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label for="goods_name" class="layui-form-label">
                    商品名
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="goods_name" name="goods_name" value="${goodsInfo.goodsName}" placeholder="请输入商品名称"
                           class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label for="goods_nums" class="layui-form-label">
                    商品数量
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="goods_nums" name="goods_nums" value="${goodsInfo.goodsNum}" placeholder="商品的数量(单位/件)"
                           class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label for="goods_price" class="layui-form-label">
                    商品单价
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="goods_price" name="goods_price" value="${goodsInfo.goodsPrice}" placeholder="商品的单价(单位/元)"
                           class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label for="goods_img" class="layui-form-label">
                    商品图片
                </label>
                <div class="layui-input-inline">
                    <img id="goods_img" src="${goodsInfo.goodsImg}" alt="加载中" style="width: 120px" height="140px"/>
                    <input type="file" onchange="changeImg(this)" style="display: none" id="uploadClick" name="goods_img" value="" class="layui-input">
                    <div id="upload_msg"  style="padding-top: 5px;padding-left: 10px"><i class="layui-icon">&#xe67c;</i>上传图片</div>
                </div>
            </div>
            <div class="layui-form-item">
                <label for="goods_desc" class="layui-form-label">
                    商品描述
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="goods_desc" name="goods_desc" value="${goodsInfo.goodsDesc}" placeholder="商品的详细描述"
                           class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">商品分类</label>
                <div class="layui-input-inline">
                    <select id="goods_type" name="goods_type">
                        <c:if test="${goodsInfo.categoryId == 1}">
                            <option value="1">衣物</option>
                            <option value="2">美妆</option>
                            <option value="3">书籍</option>
                            <option value="4">电子</option>
                            <option value="5">食物</option>
                            <option value="6">玩具</option>
                        </c:if>
                        <c:if test="${goodsInfo.categoryId == 2}">
                            <option value="2">美妆</option>
                            <option value="1">衣物</option>
                            <option value="3">书籍</option>
                            <option value="4">电子</option>
                            <option value="5">食物</option>
                            <option value="6">玩具</option>
                        </c:if>
                        <c:if test="${goodsInfo.categoryId == 3}">
                            <option value="3">书籍</option>
                            <option value="1">衣物</option>
                            <option value="2">美妆</option>
                            <option value="4">电子</option>
                            <option value="5">食物</option>
                            <option value="6">玩具</option>
                        </c:if>
                        <c:if test="${goodsInfo.categoryId == 4}">
                            <option value="4">电子</option>
                            <option value="1">衣物</option>
                            <option value="2">美妆</option>
                            <option value="3">书籍</option>
                            <option value="5">食物</option>
                            <option value="6">玩具</option>
                        </c:if>
                        <c:if test="${goodsInfo.categoryId == 5}">
                            <option value="5">食物</option>
                            <option value="1">衣物</option>
                            <option value="2">美妆</option>
                            <option value="3">书籍</option>
                            <option value="4">电子</option>
                            <option value="6">玩具</option>
                        </c:if>
                        <c:if test="${goodsInfo.categoryId == 6}">
                            <option value="6">玩具</option>
                            <option value="1">衣物</option>
                            <option value="2">美妆</option>
                            <option value="3">书籍</option>
                            <option value="4">电子</option>
                            <option value="5">食物</option>
                        </c:if>
                        <%--<option value="请选择">请选择</option>--%>
                        <%--<option value="1">衣物</option>--%>
                        <%--<option value="2">美妆</option>--%>
                        <%--<option value="3">书籍</option>--%>
                        <%--<option value="4">电子</option>--%>
                        <%--<option value="5">食物</option>--%>
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <button id="update_btn" class="layui-btn">
                    修改
                </button>
            </div>
        </form>
    </div>
</div>
</body>
<script src="./js/jquery-3.1.0.min.js" type="text/javascript"></script>
<script>
    function changeImg(e){
        document.getElementById("goods_img").src=window.URL.createObjectURL(e.files[0]);
    }

    layui.use(['form', 'layer'], function () {
        var form = layui.form,
            layer = layui.layer;
    });
    $(function () {
        $("#upload_msg").click(function () {
            $("#uploadClick").click();
        });

        $("#update_btn").click(function () {
            var goodsId = $("#goods_id").val();
            var goodsStatus = $("#goods_status").val();
            var goodsName = $("#goods_name").val();
            var goodsNum = $("#goods_nums").val();
            var goodsPrice = $("#goods_price").val();
            //var goodsImg = $("#goods_img").val();
            var goodsDesc = $("#goods_desc").val();
            var categoryId = $("#goods_type").val();
            $.ajax({
                url: "./updateGoods",
                type: "post",
                data: {
                    goodsId: goodsId,
                    goodsStatus:goodsStatus,
                    goodsName: goodsName,
                    goodsNum: goodsNum,
                    goodsPrice: goodsPrice,
                    //goodsImg: goodsImg,
                    goodsDesc: goodsDesc,
                    categoryId: categoryId
                },
                success: function (res) {
                    if (res.data === "修改成功") {
                        layer.alert("修改成功", {
                                icon: 6
                            },
                            function () {
                                //关闭当前frame
                                xadmin.close();
                                // 可以对父窗口进行刷新
                                xadmin.father_reload();
                            });
                    } else {
                        layer.msg("修改失败");
                    }
                },
                error: function () {
                    alert("404.html页面");
                }
            });
        });
    });
</script>
</html>

